package com.apiit.webserviceclient.activities;

import java.util.HashMap;
import java.util.Map;

import com.apiit.webserviceclient.R;
import com.apiit.webserviceclient.R.layout;
import com.apiit.webserviceclient.R.menu;
import com.apiit.webserviceclient.utility.BPEL_Process;
import com.apiit.webserviceclient.utility.BPEL_Request;
import com.apiit.webserviceclient.utility.BPEL_Response;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class UpdatePagolProfile extends Activity implements OnClickListener{
	
	Button back;
	Button reset;
	Button submit;
	
	TextView txtstuID;
	TextView txtintakeID;
	TextView txtstuname;
	EditText txtemail;
	EditText txtcontactno;
	TextView txtprojtitle;
	TextView txtsupervisor;
	TextView txtadvisor;
	TextView txtPPFSubmission;
	TextView txtPSFSubmission;
	TextView txtmidpointinterview;
	TextView txtprojectsubmissiondate;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_update_pagol_profile);
		
		back = (Button) findViewById(R.id.btnback);
		reset = (Button) findViewById(R.id.btnprofreset);
		submit = (Button) findViewById(R.id.btnsubmitprof);
		
		txtstuID = (TextView) findViewById(R.id.txtUpdatestuID);
		txtintakeID = (TextView) findViewById(R.id.txtUpdateintakeID);
		txtstuname = (TextView) findViewById(R.id.txtUpdatestuname);
		txtemail = (EditText) findViewById(R.id.editemail);
		txtcontactno = (EditText) findViewById(R.id.editcontactno);
		txtprojtitle = (TextView) findViewById(R.id.txtUpdateprojtitle);
		txtsupervisor = (TextView) findViewById(R.id.txtUpdatesupervisor);
		txtadvisor = (TextView) findViewById(R.id.txtUpdateadvisor);

		
		Intent intename = getIntent();
		String studID = intename.getStringExtra("studentID");
		String intakeID = intename.getStringExtra("intakeID");
		String studName = intename.getStringExtra("studName");
		String email = intename.getStringExtra("email");
		//String contactNo = intename.getStringExtra("contactNo");
		String pojTitle = intename.getStringExtra("projTitle");
		String supervisor = intename.getStringExtra("supervisor");
		String advisor = intename.getStringExtra("advisor");
//		
		txtstuID.setText(studID);
		txtintakeID.setText(intakeID);
		txtstuname.setText(studName);
		txtemail.setText(email);
		//txtcontactno.setText(contactNo);
		txtprojtitle.setText(pojTitle);
		txtsupervisor.setText(supervisor);
		txtadvisor.setText(advisor);

		
		//txtfieldEmail=charini.nipunika@yahoo.com&txtfieldPhone=
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.update_pagol_profile, menu);
		return true;
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == back) {
			Intent i = new Intent(this, Pagol.class);
			startActivity(i);
		}
		if (v == submit) {
			BPEL_Process bpelProcess = new BPEL_Process();
			BPEL_Request request = new BPEL_Request();
			request.setUrl("http://webspace1.apiit.lk/pagol15/www/student_pp.asp?profilePID=savProfile");

			Map<String, String> xpathMap = new HashMap<String, String>();
//			xpathMap.put("title", "//title---");
//			xpathMap.put("studentID","/html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[2]/td[3]---");
//			xpathMap.put("intakeID","/html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[3]/td[3]---");
//			xpathMap.put("studentName","/html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[4]/td[3]---");
			///html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[6]/td[3]/input---value 
			xpathMap.put("email","/html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[5]/td[3]/input---value");
//			xpathMap.put("contactNo","html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[6]/td[3]/input---value");
//			xpathMap.put("proTitle","/html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[7]/td[3]---");
//			xpathMap.put("supervisor","/html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[8]/td[3]---");
//			xpathMap.put("advisor","/html[1]/body[1]/center[1]/table[1]/tr[1]/td[1]/table[1]/tr[9]/td[3]---");

			request.setXpathMap(xpathMap);
			//txtfieldEmail=charini.nipunika@yahoo.com&txtfieldPhone=
			Map<String, String> parametersMap = new HashMap<String, String>();
			parametersMap.put("txtfieldEmail", txtemail.getText().toString());
			parametersMap.put("txtfieldPhone", txtcontactno.getText().toString());
			request.setParametersMap(parametersMap);

			request.setType("POST");

			BPEL_Response response = null;
			try {
				response = bpelProcess.doRequest(request);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Intent i = new Intent(this, Pagol.class);
			startActivity(i);
		}
	}

}
